const mongoose = require('mongoose')
const config = require('../config/index')
const { Wechat } = require('../wechat-lib')

import WechatOAuth from '../wechat-lib/oauth'



const Token = require('../schema/wechat/token.js').Token;
const Ticket = require('../schema/wechat/ticket.js').Ticket;

const wechatConfig = {
  wechat: {
    appID: config.wechat.appID,
    appSecret: config.wechat.appSecret,
    token: config.wechat.token,
    getAccessToken: async () => await Token.getAccessToken(),
    saveAccessToken: async (data) => await Token.saveAccessToken(data),
    getTicket: async () => await Ticket.getTicket(),
    saveTicket: async (data) => await Ticket.saveTicket(data)
  }
}



 export const getWechat = () => {
  const wechatClient = new Wechat(wechatConfig.wechat)

  return wechatClient
}

//module.exports={
//	getWechat
//}
// 

 export const getOAuth = () => {
  const oauth = new WechatOAuth(wechatConfig.wechat)

  return oauth
 }
